<template>
  <a-card :bordered="false">
    <div style="display: flex; justify-content: space-between">
      <!-- 操作按钮区域 -->
      <div class="table-operator">
        <a-dropdown v-if="selectedRowKeys.length > 0">
          <a-menu slot="overlay">
            <a-menu-item key="1" @click="batchDel"><a-icon type="delete" v-has="'agency:delete'" />删除</a-menu-item>
          </a-menu>
          <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
        </a-dropdown>
      </div>
      <!-- 查询区域 -->
      <div class="table-page-search-wrapper">
        <a-form layout="inline" @keyup.enter.native="searchQuery">

              <a-form-item label="来源类型" style="margin-right: 10px">
                <a-select
                  v-model="queryParam.sourceTpye"
                  style="width: 120px"
                  :options="[
                    { label: '项目返佣', value: '0' },
                    { label: '充值返佣', value: '1' },
                  ]"
                  allowClear
                  placeholder="请选择"
                  @change="searchQuery"
                />
              </a-form-item>

              <a-form-item label="来源订单号">
                <a-input
                  placeholder="请输入来源订单号"
                  v-model="queryParam.sourceOrderNo"
                  @pressEnter="searchQuery"
                ></a-input>
              </a-form-item>

              <a-form-item label="推广商名称">
                <a-input
                  placeholder="请输入推广商名称"
                  v-model="queryParam.distributionName"
                  @pressEnter="searchQuery"
                ></a-input>
              </a-form-item>

              <a-form-item label="推广商编号">
                <a-input
                  placeholder="请输入推广商编号"
                  v-model="queryParam.distributionId"
                  @pressEnter="searchQuery"
                ></a-input>
              </a-form-item>

              <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
                <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
                <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
                <!-- <a-button type="primary" icon="download" @click="handleExportXls('服务商表')" style="margin-left: 8px"
                  >导出</a-button
                >
                <a-upload
                  name="file"
                  :showUploadList="false"
                  :multiple="false"
                  :headers="tokenHeader"
                  :action="importExcelUrl"
                  @change="handleImportExcel"
                >
                  <a-button type="primary" icon="import" style="margin-left: 8px">导入</a-button>
                </a-upload> -->
              </span>

        </a-form>
      </div>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a
        >项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :scroll="{ x: 'auto' }"
        class="j-table-force-nowrap"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
        @change="handleTableChange"
      >
        <!-- 营业执照 -->
        <template slot="businessLicenseSlot" slot-scope="text, record">
          <div class="anty-img-wrap">
            <a-avatar shape="square" :src="getAvatarView(record.businessLicense)" />
          </div>
        </template>
        <!-- 身份证照片 -->
        <template slot="avatarslot" slot-scope="text, record">
          <div class="anty-img-wrap">
            <a-avatar shape="square" :src="getAvatarView(record.idCardImg)" />
          </div>
        </template>
        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)" v-has="'agency:edit'">编辑</a>
          <a-divider type="vertical" v-has="'agency:edit'" />
          <!-- <a @click="mapEdit(record)" v-has="'user:map'">定位</a>
          <a-divider type="vertical" v-has="'user:map'"/> -->
          <a @click="userEdit(record)" v-has="'user:binding'">绑定用户</a>
          <a-divider type="vertical" v-has="'user:binding'" />
          <a-dropdown v-has="'agency:delete'">
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </a-table>
    </div>
    <!-- table区域-end -->
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import Area from '@/components/_util/Area'
import { getFileAccessHttpUrl } from '@/api/manage'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import Speech from 'speak-tts'
export default {
  name: 'xhdjCommissionList',
  mixins: [JeecgListMixin],

  data() {
    return {
      speech: null,
      description: '服务商表管理页面',
      queryParam: {
        agencyCode: '',
        province: undefined,
        area: undefined,
        city: undefined,
      },
      // 表头
      columns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '推广商绑定编码',
          align: 'center',
          dataIndex: 'distributionId',
        },
        {
          title: '推广商名称',
          align: 'center',
          dataIndex: 'distributionName',
        },
        {
          title: '收支金额',
          align: 'center',
          dataIndex: 'amount',
        },
        {
          title: '创建日期',
          align: 'center',
          dataIndex: 'createTime',
        },

        {
          title: '来源订单号',
          align: 'center',
          dataIndex: 'sourceOrderNo',
        },
        {
          title: '来源类型',
          align: 'center',
          dataIndex: 'sourceTpye',
          customRender: (text, record) => {
            return record.sourceTpye == 1 ? '充值返佣' : '项目返佣'
          },
        },
      ],
      url: {
        list: '/xhdjDistributionIncomeExpenses/commissionList',
        delete: '/xhdjAgency/delete',
        deleteBatch: '/xhdjAgency/deleteBatch',
        exportXlsUrl: 'xhdjAgency/exportXls',
        importExcelUrl: 'xhdjAgency/importExcel',
      },
      all: [], // 地址信息
      allList: [], // 省份数据
      citys: [],
      cityss: [],
    }
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  created() {
    this.all = new Area().all
    this.allList = this.all.filter((res) => res.index == 1)
    this.queryParam = {
      agencyCode: '',
      province: undefined,
      area: undefined,
      city: undefined,
    }
    this.speech = new Speech()
    this.speech.setLanguage('zh-CN')
    this.speech.init().then(() => {})
  },
  methods: {
    getAvatarView: function (avatar) {
      return getFileAccessHttpUrl(avatar)
    },
    // 下拉框格式转换
    formatData(array) {
      var arr = []
      arr = array.forEach((res) => {
        res.value = res.id
        res.label = res.text
      })
      return array
    },
    // 城区中文显示
    cityGS(value) {
      var a = []
      a = this.all.filter((res) => res.id == value)
      if (a && a.length > 0) {
        return a[0].text
      } else {
        return '无'
      }
    },
    mapEdit(record) {
      this.speech
        .speak({ text: '你有新的订单' })
        .then(() => {
          console.log('读取成功')
        })
        .catch(() => {})
      this.$refs.mapdialog.edit(record)
      this.$refs.mapdialog.title = '定位'
      // this.$refs.modalmapdialogForm.disableSubmit = false;
    },
    userEdit(record) {
      this.$refs.userDialog.edit(record)
      this.$refs.userDialog.title = '用户绑定'
      // this.$refs.modalmapdialogForm.disableSubmit = false;
    },
    cityClick() {
      this.queryParam.area = null
      this.queryParam.city = null
      this.citys = this.all.filter((res) => res.pid == this.queryParam.province)
    },
    citysClicks() {
      this.queryParam.area = null
      this.cityss = this.all.filter((res) => res.pid == this.queryParam.city)
    },
    clicks(value) {
      this.$forceUpdate()
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';

.ant-form {
  display: flex;
  justify-content: flex-end;
}
.ant-row {
  display: flex;
  justify-content: flex-end;
}
</style>
